from typing import Any, ClassVar, Callable

from pydantic import BaseModel
from fastapi.responses import JSONResponse


class JsonModel(BaseModel):
	code: int
	data: Any
	msg: str
	to_response: ClassVar[Callable[..., Any]]

	def to_response(self, headers=None):
		return JSONResponse(content=self.dict(), headers=headers, status_code=self.code)


"""
200：success

300：传参错误

400：查找的数据不存在
401：用户鉴权
402：功能鉴权
403：数据重复
404：接口不存在
"""